<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>v-for指令</title>
</head>
<body>
<div id="app">
    <input type="button" value="添加数据" @click="add">
    <input type="button" value="移除数据" @click="remove">
    <ul>
        <li v-for="(item,index) in arr">
            我去过的城市 {{index+1}} - {{item}}
        </li>
    </ul>

    <h1>我的兴趣爱好:</h1>
    <h2 v-for="item in like" v-bind:title="item.name">
        {{ item.name }}
    </h2>
</div>

<!-- 生产环境版本，优化了尺寸和速度 -->
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script type="text/javascript">
    var vue = new Vue({
        el: "#app",
        data: {
            arr: ["北京", "上海", "深圳", "香港"],
            like: [
                {name: "编程"},
                {name: "旅游"}
            ]
        },
        methods: {
            add: function () {
                this.like.push({name: "开车"})
            },
            remove: function () {
                this.like.shift();//从左边移除
            }
        }
    })
</script>
</body>
</html>
